package bombermanGame;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class GameMenuState extends BasicGameState implements ComponentListener {
	
	public static int ID = 4;
	/** the game holding this state*/
	private StateBasedGame game;
	/** the container of the game */
	private GameContainer container;
	private Image background;
	private Image logo;
	private Image bombermanLogo;
	private Image startGameButton;
	private Image optionsButton;
	private Image highScoresButton;
	private Image howToPlayButton;
	private Image exitButton;
	
	private MouseOverArea startGameButtonMouseOverArea;
	private MouseOverArea optionsButtonMouseOverArea;
	private MouseOverArea highScoresButtonMouseOverArea;
	private MouseOverArea howToPlayButtonMouseOverArea;
	private MouseOverArea exitButtonMouseOverArea;

	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		this.game = game;
		this.container = container;
		
		background = new Image("/images/GameMenuImages/background.jpg");
		logo = new Image("/images/GameMenuImages/logo.png");	
		bombermanLogo = new Image("images/GameMenuImages/bombermanLogo.gif");
		
		startGameButton = new Image("images/GameMenuImages/startGameButton.png");
		optionsButton = new Image("images/GameMenuImages/optionsButton.png");
		highScoresButton = new Image("images/GameMenuImages/highScoresButton.png");
		howToPlayButton = new Image("images/GameMenuImages/howToPlayButton.png");
		exitButton = new Image("images/GameMenuImages/exitButton.png");
		
		container.setMouseCursor("images/GameMenuImages/cursor.tga", 0, 0);
		
		// start game button area
		startGameButtonMouseOverArea = new MouseOverArea(container, startGameButton, 400, 270, startGameButton.getWidth(), startGameButton.getHeight(), this);
		startGameButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		startGameButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// options button area
		optionsButtonMouseOverArea = new MouseOverArea(container, optionsButton, 400, 320, optionsButton.getWidth(), optionsButton.getHeight(), this);
		optionsButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		optionsButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// howToPlay button area
		howToPlayButtonMouseOverArea = new MouseOverArea(container, howToPlayButton, 400, 370, howToPlayButton.getWidth(), howToPlayButton.getHeight(), this);
		howToPlayButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		howToPlayButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// high scores button area
		highScoresButtonMouseOverArea = new MouseOverArea(container, highScoresButton, 400, 420, highScoresButton.getWidth(), highScoresButton.getHeight(), this);
		highScoresButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		highScoresButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));

		// exit button area
		exitButtonMouseOverArea = new MouseOverArea(container, exitButton, 400, 470, exitButton.getWidth(), exitButton.getHeight(), this);
		exitButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		exitButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		background.draw(0, 0);
		logo.draw(70, 100);
		bombermanLogo.draw(140, 220);
		
		startGameButtonMouseOverArea.render(container, g);
		optionsButtonMouseOverArea.render(container, g);
		highScoresButtonMouseOverArea.render(container, g);
		howToPlayButtonMouseOverArea.render(container, g);
		exitButtonMouseOverArea.render(container, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		
	}

	@Override
	public int getID() {
		return ID;
	}

	@Override
	public void componentActivated(AbstractComponent source) {
		if(source == startGameButtonMouseOverArea) {
			game.enterState(GamePlayState.ID);
		}
		else if(source == optionsButtonMouseOverArea) {
			game.enterState(OptionsMenuState.ID);
		}
		else if(source == highScoresButtonMouseOverArea) {
			// high score menu ye git
		}
		else if(source == exitButtonMouseOverArea) {
			container.exit();
		}
	}

}
